package com.focusai.efairy.ui.adapter.warn;

import android.app.Activity;

import com.focusai.efairy.R;
import com.focusai.efairy.model.warn.AlarmItem;
import com.focusai.efairy.network.Image.ImageLoaderFactory;
import com.focusai.efairy.ui.adapter.base.BaseRecyclerAdapter;
import com.focusai.efairy.ui.adapter.base.BaseRecyclerViewHolder;
import com.focusai.efairy.ui.widget.ninegridview.NineGridTestLayout;
import com.focusai.efairy.utils.ActivityUtils;
import com.focusai.efairy.utils.StrByCodeUtils;

import java.util.ArrayList;

/**
 * Created by luo_guangwen on 2017/9/12.
 */

public class AlarmRecordeAdapter extends BaseRecyclerAdapter<AlarmItem> {

    private Activity context;

    public AlarmRecordeAdapter(Activity context) {
        super(context);
        this.context = context;
    }

    @Override
    protected int getItemLayoutId() {
        return R.layout.item_maintain;
    }

    @Override
    protected void onBindBaseRecyclerViewHolder(BaseRecyclerViewHolder holder, final int position) {
        final AlarmItem item = mList.get(position);
        holder.setText(R.id.text_heard_name, item.efairyuser_nickname);
        holder.setText(R.id.text_heard_content, item.efairydevice_name);
        holder.setText(R.id.text_content, item.efairyalarmrecord_content);
        holder.setText(R.id.text_food_time, item.efairyalarmrecord_add_time);
        String tip = StrByCodeUtils.getStatusByAlarmId(item.efairyalarmrecord_alarm_id) + "  ";
        if (item.efairyalarmrecord_is_handle == 1) {
            tip += "隐患已排除";
        } else {
            tip += "隐患未排除";
        }
        holder.setText(R.id.text_heard_tip, tip);
        ImageLoaderFactory.getImageLoader().loadImage(mContext, holder.getImageView(R.id.iv_user_avater), item.efairyuser_headimg_url, R.drawable.user_default_icon, false);
        NineGridTestLayout layout = (NineGridTestLayout) holder.getView(R.id.layout_nine_grid);
        layout.setUrlList(item.efairyalarmrecord_imgurl_list);
        layout.setOnImageItemClick(new NineGridTestLayout.OnImageItemClick() {
            @Override
            public void onImageItemClick(int position, String url, ArrayList<String> urlList) {
                ActivityUtils.openPhotoPagerActivity(context, 0, position, urlList, false);
            }
        });
    }

}
